/*
 * Copyright 2009 Original Author(s)
 * 
 * This file is part of Kommando
 * 
 * Kommando is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Kommando is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Kommando.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.kommando.core.hotkey;

import org.kommando.core.command.Command;

/**
 * Base implementation of {@link HotkeyService}.
 * <p>
 * Implementors must implement {@link #doRegisterHotkey(Hotkey)} and
 * {@link #doUnregisterHotkey(Hotkey)}, and call the
 * {@link #hotkeyPressed(Hotkey)} when necessary.
 * 
 * @author Peter De Bruycker
 */
public abstract class AbstractHotkeyService implements HotkeyService {

	private HotkeyCallback callback;

	@Override
	public void init(HotkeyCallback callback) {
		this.callback= callback;
	}

	/**
	 * Subclasses need to call this method so the {@link Command} associated
	 * with the {@link Hotkey} is executed.
	 * 
	 * @param key
	 *            the hotkey
	 */
	protected void hotkeyPressed(Hotkey key) {
		callback.hotkeyPressed(key);
	}
}
